package com.ycp.erp.brand.ui.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.utils.TextUtils;
import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.model.extra.DefaultExtra;
import com.one.common.utils.StringUtils;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.widget.ClearEditView;
import com.one.common.view.widget.MyTitleBar;
import com.ycp.erp.R;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;

/**
 * Class Des:添加品牌
 * Created by bjh on 2021/8/25.
 */
@Route(path = RouterPath.ADD_BRAND)
public class AddBrandActivity extends BaseActivity {
    @BindView(R.id.tvBrandName)
    ClearEditView tvBrandName;
    @BindView(R.id.etSortValue)
    ClearEditView etSortValue;
    @BindView(R.id.tvAddRemarks)
    TextView tvAddRemarks;
    @BindView(R.id.tvRemarks)
    TextView tvRemarks;
    @BindView(R.id.tvSubmit)
    TextView tvSubmit;
    public static final int REQUEST_CODE_REMARK = 101;
    @Override
    protected void initPresenter() {

    }
    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("添加品牌").hideLine();
    }
    @Override
    public int getLayoutResId() {
        return R.layout.activity_add_brand;
    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        super.initView();
        tvSubmit.setText("确认提交");
        RxView.clicks(tvSubmit).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
            finish();
        });
        RxView.clicks(tvAddRemarks).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
            if (tvRemarks.getText().toString().equals("暂无备注")){
                RouterManager.getInstance().goForResult(this,RouterPath.BRAND_REMARK,REQUEST_CODE_REMARK,new DefaultExtra(""));
            }else {
                RouterManager.getInstance().goForResult(this,RouterPath.BRAND_REMARK,REQUEST_CODE_REMARK,new DefaultExtra(tvRemarks.getText().toString()));
            }

        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            DefaultExtra extra = (DefaultExtra) data.getSerializableExtra(DefaultExtra.getExtraName());
            String remark = extra.getStr();
            if (StringUtils.isNotBlank(remark)){
                tvRemarks.setText(remark);
                tvRemarks.setTextColor(getResources().getColor(R.color.text_color_black_33));
                tvAddRemarks.setText("修改备注");
            }else {
                tvRemarks.setText("暂无备注");
                tvRemarks.setTextColor(getResources().getColor(R.color.text_color_99));
                tvAddRemarks.setText("添加备注");
            }
        }
    }
}
